package com.metaverse.backend.task;

import com.metaverse.backend.config.RedisCacheKey;
import com.metaverse.backend.config.RedisLockKey;
import com.metaverse.backend.lock.RedisLockable;
import com.metaverse.backend.repo.PlayerDataRepo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;


/**
 * 定时清理玩家数据
 *
 */
@Slf4j
@AllArgsConstructor
@Service
public class PlayerDataCleanTask {

    private PlayerDataRepo playerDataRepo;

    private RedisTemplate redisTemplate;


    /**
     *
     * 清理排行数据
     *
     */
    @Scheduled(cron = "0 0 3 5 * ?")
    @RedisLockable(prefix= RedisLockKey.SCHEDULE_TASK, ignoreFail = true)
    public void cleanAll(){
        log.info("清理世界排行数据...");
        redisTemplate.delete(RedisCacheKey.RANKING);
        playerDataRepo.deleteAll();
    }



}
